package com.example.back.Repository;

import com.example.back.Entity.Auction;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Repository
public interface AuctionRepository extends JpaRepository<Auction,Long> {
    Auction findAuctionByAuctionId(long auctionId);
    @Override
    List<Auction> findAll();
    boolean deleteAuctionByAuctionId(long aid);
    Page<Auction> findAllBySellerId(Pageable pageable,long salerId);
    Page<Auction> findAllByAuctionNameContains(Pageable pageable,String auctionNameContains);
    Page<Auction> findAllByAuctionTag(Pageable pageable,String auctionTag);
    Page<Auction> findAllByAuctionTagAndAuctionNameContains(Pageable pageable,String auctionTag,String auctionNameContains);
    Page<Auction> findAllByAuctionTimeStampBetween(Pageable pageable,long greaterThan,long lessThan);
    @Transactional
    @Modifying
    @Query(value = "update Auction auction set auction.nowPrice = auction.nowPrice+:addPrice,auction.nowWinId=:userId,auction.nowWinName=:userName where auction.auctionId=:auctionId")
    void updateAuctionNowPrice(int addPrice,long auctionId,long userId,String userName);

}
